package cn.tedu.front.search.service.impl;

import cn.tedu.front.search.dao.cache.ISearchJobCacheRepository;
import cn.tedu.front.search.dao.persist.repository.ISearchJobRepository;
import cn.tedu.front.search.pojo.param.SearchKeywordsParam;
import cn.tedu.front.search.pojo.vo.SearchJobVO;
import cn.tedu.front.search.service.ISearchJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchJobService implements ISearchJobService {
    @Autowired
    private ISearchJobRepository searchJobRepository;
    @Autowired
    private ISearchJobCacheRepository cacheRepository;
    @Override
    public List<SearchJobVO> select(SearchKeywordsParam param) {
        List<SearchJobVO> cacheList = cacheRepository.selectKeyword(param);
        if (cacheList.size()==0){
            List<SearchJobVO> searchJobVOS = searchJobRepository.selectKeyword(param);
            cacheRepository.save(searchJobVOS,param);
            return searchJobVOS;
        }
        return cacheList;
    }
}
